﻿<!DOCTYPE html>

<html>

<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    @Scripts.Render("~/Resource/js/fe.head.js")
</head>

<body>
    <div id="app" v-cloak>
        <el-container class="list_pagecontainer">
            <el-header>
                <el-row>
                    <el-col :span="24">
                        <div class="list_searchcontainer">
                            <el-input placeholder="请输任务名称" v-model="taskName" class="list_searchinput">
                            </el-input>
                            <el-button type="primary" v-on:click="bindGrid" icon="el-icon-search">搜索</el-button>
                        </div>
                    </el-col>
                </el-row>
            </el-header>
            <el-main>
                <common-table :data="tableData" :page-Index="pageIndex" :page-Size="pageSize" :total="total" :table-Height="tableHeight"
                    :show-Delete="false" v-on:on-load="bindGrid" v-on:handle-edit="edit" v-on:on-pageindexchange="pageIndexChange"
                    ref="table">
                    <template slot="column">
                        <el-table-column prop="TaskName" label="任务名称">
                        </el-table-column>
                        <el-table-column label="任务类型" width="100" header-align="center" align="center">
                            <template slot-scope="scope">
                                <span v-if="scope.row.TaskExecuteType==100">循环任务</span>
                                <span v-else>Corn表达式任务</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="JobClassName" label="任务执行类">
                        </el-table-column>
                        <el-table-column label="状态" width="100" header-align="center" align="center">
                            <template slot-scope="scope">
                                <span v-if="scope.row.TaskStatus==1">启用</span>
                                <span v-else>禁用</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="TaskExplain" label="任务描述">
                        </el-table-column>
                        <el-table-column prop="OrderNum" label="排序" width="100">
                        </el-table-column>
                    </template>
                </common-table>
            </el-main>
            <el-footer>
                <el-row>
                    <el-col :span="24">
                        <div class="list_opcontainer">
                            <el-button type="primary" v-on:click="add">添加任务</el-button>
                            <el-button type="danger" v-on:click="batchDelete">删除选中</el-button>
                        </div>
                    </el-col>
                </el-row>
            </el-footer>
        </el-container>
    </div>
</body>
@Scripts.Render("~/Resource/js/fe.foot.js")

</html>
<script>
    var tableUrl = GetRootPath() + "Frame/Task/FindList"
    var batchDeletetUrl = GetRootPath() + "Frame/Task/OperateBatchDelete"
    var pageData = {
        //data
        tableData: [],
        //page
        pageIndex: 1,
        pageSize: 10,
        total: 0,
        //search
        taskName: "",
        //css
        tableHeight: 0,
    };
    new Vue({
        el: '#app',
        data: pageData,
        mounted: function () {
            pageData.tableHeight = CaculateTableHeight();
        },
        methods: {
            pageIndexChange: function (val) {
                this.pageIndex = val
            },
            bindGrid: function () {
                bindGrid();
            },
            add: function () {
                OpenTopDialog('taskadd', '添加任务', 'Frame/Task/Add',
                    500, 800, bindGrid)
            },
            edit: function (index, row) {
                OpenTopDialog('taskedit', '编辑任务', 'Frame/Task/Edit?RowGuid=' + row.RowGuid,
                    500,
                    800,
                    bindGrid)
            },
            batchDelete: function () {
                var selectRow = this.$refs.table.getSelectRow();
                if (selectRow.length == 0) {
                    OpenWaring('提示', '请选择删除的数据')
                } else {
                    OpenConfirm('提示', '确认删除选中的数据？', function () {
                        var KeyGuidList = "";
                        selectRow.forEach(element => {
                            KeyGuidList += element.RowGuid + ";";
                        });
                        var data = {
                            KeyGuidList: KeyGuidList
                        }
                        JsonAjaxPost(batchDeletetUrl, JSON.stringify(data), function (data,
                            status) {
                            if (data.code == 0) {
                                OpenSuccess('提示', '删除成功！', bindGrid)
                            } else {
                                OpenFail('提示', data.msg)
                            }
                        })
                    })
                }
            },
        }
    })

    function bindGrid() {
        var data = {
            PageIndex: pageData.pageIndex,
            PageSize: pageData.pageSize,
            TaskName: pageData.taskName
        }
        JsonAjaxPost(tableUrl, JSON.stringify(data), function (data, status) {
            Vue.set(pageData, "tableData", data.data);
            Vue.set(pageData, "total", data.total)
        })
    }
</script>